package com.you.weixinpay.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.you.weixinpay.domain.entity.TOrderInfo;
import com.you.weixinpay.enums.OrderStatus;
import com.you.weixinpay.properties.WeChatProperties;
import com.you.weixinpay.result.Result;
import com.you.weixinpay.service.TOrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yzm
 * @since 2025-06-15
 */
@RestController
@RequestMapping("/api/order-info")
@RequiredArgsConstructor
@Tag(name = "订单")
public class TOrderInfoController {
    private final WeChatProperties weChatProperties;
    private final TOrderInfoService tOrderInfoService;

    @GetMapping("/list")
    @Operation(summary = "查询订单列表")
    public Result<IPage<TOrderInfo>> list(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "",required = false) String title) {

        Page<TOrderInfo> page = new Page<>(pageNum, pageSize);
        Page<TOrderInfo> resultPage = tOrderInfoService.getList(page, title);
        return Result.success(resultPage);
    }
    @GetMapping("/query-order-status/{orderNo}")
    @Operation(summary = "查询订单状态")
    public Result queryOrderStatus(@PathVariable String orderNo){

        String orderStatus = tOrderInfoService.getOrderStatus(orderNo);
        if(OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return Result.success().setMessage("支付成功"); //支付成功
        }

        return Result.success().setCode(101).setMessage("支付中......"); //特殊的状态码，前端会进行轮询查询
    }
}

